﻿
using System;
using System.Collections.Generic;
using System.Linq;
using Test30.Util;

namespace Test30.Engine
{
    public class RepeatDrop<T> : IDrop<T>
    {
        public RepeatDrop(NotNull<Roller> repeat, IDrop<T> drop)
        {
            _repeat = repeat;
            _drop = drop ?? throw new ArgumentNullException($"drop");
        }

        #region IDrop Members

        public IEnumerable<T> Create(int level)
        {
            foreach (int dummy in Enumerable.Range(0, _repeat.Roll()))
            {
                foreach (var item in _drop.Create(level))
                {
                    yield return item;
                }
            }
        }

        #endregion

        private readonly Roller _repeat;
        private readonly IDrop<T> _drop;
    }

}
